﻿using DynORM.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DynORM.BLLMapper.Helpers
{
    public class LazyLoadStatus
    {
        public static void MarkAsGhost(object bllObj)
        {
            if ((bllObj is BLLSuperType))
                ((BLLSuperType)bllObj).MarkAsGhost();
        }

        public static void MarkAsLoading(object bllObj)
        {
            if ((bllObj is BLLSuperType))
                ((BLLSuperType)bllObj).MarkAsLoading();
        }

        public static void MarkAsLoaded(object bllObj)
        {
            if (!(bllObj is BLLSuperType))
                ((BLLSuperType)bllObj).MarkAsLoaded();
        }

        public static bool IsLoaded(object bllObj)
        {
            if ((bllObj is BLLSuperType))
                return ((BLLSuperType)bllObj).IsLoaded;
            else
                return true; //just to skip the check for POCOs
        }

        public static bool IsLoading(object bllObj)
        {
            if ((bllObj is BLLSuperType))
                return ((BLLSuperType)bllObj).IsLoading;
            else
                return false; //just to skip the check for POCOs
        }

        public static bool IsGhostOrLoading(object bllObj)
        {
            if ((bllObj is BLLSuperType))
                return (((BLLSuperType)bllObj).IsGhost || ((BLLSuperType)bllObj).IsLoading);
            else
                return false; //just to skip the check for POCOs
        }

    }
}
